package file_1;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class FileDemo {
    public static void main(String[] args) throws IOException {
        checkFileName();
    }

    public static void checkFileName() throws IOException {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入文件名：");
            String fileName = scanner.nextLine();
            File file = new File(fileName);
            if (file.exists()) {
                System.out.println("该文件已存在，请重新更换名字");
            } else {
                File file1 = new File(fileName);
                file1.createNewFile();
                System.out.println(file1.getName());
                break;
            }
        }
    }
}
